package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.DUserExtService;
import cn.huiyunche.base.service.mappers.DUserExtMapper;
import cn.huiyunche.base.service.model.DUserExt;
import cn.huiyunche.base.service.model.DUserExtExample;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by jxy on 16/12/12.
 */
@Service
public class DUserExtServiceImpl implements DUserExtService {

    private static final Logger LOGGER = LoggerFactory.getLogger(DUserExtServiceImpl.class);

    @Autowired
    private DUserExtMapper dUserExtMapper;

    public int insertSelective(DUserExt dUserExt) {
        return dUserExtMapper.insertSelective(dUserExt);
    }

    public int deleteByUserId(Long userId) {
        return dUserExtMapper.deleteByUserId(userId);
    }

    public List<DUserExt> selectByExample(DUserExtExample example) {
        return dUserExtMapper.selectByExample(example);
    }

    public int updateByPrimaryKeySelective(DUserExt record) {
        return dUserExtMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public DUserExt selectByUserId(Long dUserId) {
        LOGGER.info("DUserExtServiceImpl.selectByUserId param : {}", dUserId);

        if (null == dUserId || 0 == dUserId.longValue()) {
            LOGGER.error("DUserExtServiceImpl.selectByUserId param dUserId must not be null");
            throw new IllegalArgumentException("D用户主键不能为空");
        }

        DUserExtExample extExample = new DUserExtExample();
        extExample.createCriteria().andUserIdEqualTo(dUserId);

        List<DUserExt> list = dUserExtMapper.selectByExample(extExample);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }

        return null;
    }

    @Override
    public String selectByIdCard(String idCard) {
        return dUserExtMapper.selectByIdCard(idCard);
    }


}
